<!--
 * Description: CBOM Report
 * Company: 联宝（合肥）电子科技有限公司
 * Author: Qiuxue.Wu
 * Date: 2020/10/27 02:52
-->

<template>
  <BaseWrap>
    <!-- 基础数据 -->
    <CbomReportBaseData />
    <!-- 详情数据 -->
    <CbomReportDetailData
      v-if="isDetailData"
      :isDetailData.sync="isDetailData"
      :rowData="currentRowData"
      @cancel="isDetailData = false"
    />
    <!-- 新增 -->
    <BaseDialog
      v-if="addDialogVisible"
      :title="$t('dialog.add')"
      :visible.sync="addDialogVisible"
      width="800px"
    >
      <CbomAdd :projectList="projectList" @cancel="addDialogVisible = false" />
    </BaseDialog>
    <!--编辑-->
    <BaseDialog
      v-if="editDialogVisible"
      :title="$t('dialog.edit')"
      :visible.sync="editDialogVisible"
      width="800px"
    >
      <CbomEdit
        :projectList="projectList"
        :rowData="currentRowData"
        @cancel="editDialogVisible = false"
      />
    </BaseDialog>
  </BaseWrap>
</template>
<script>
import CbomReportBaseData from './components/CbomReportBaseData'
import CbomReportDetailData from './components/CbomReportDetailData'
import CbomAdd from './components/CbomAdd'
import CbomEdit from './components/CbomEdit'
import { projectSimpleList } from '@/api/quote/project'

export default {
  name: 'CbomDM',
  components: { CbomReportBaseData, CbomReportDetailData, CbomAdd, CbomEdit },
  data() {
    return {
      // 是否显示详情数据
      isDetailData: false,
      // 当前行的数据
      currentRowData: {},
      // 新增标识
      addDialogVisible: false,
      // 编辑标识
      editDialogVisible: false,
      // 专案数据
      projectList: []
    }
  },

  created() {
    /** 加载专案 */
    this.getProjectList()
    /** 新增数据 */
    this.$bus.$on('cbom-add', () => {
      this.addDialogVisible = true
    })
    /** 修改数据 */
    this.$bus.$on('cbom-edit', (index, rowData) => {
      this.currentRowData = rowData
      this.editDialogVisible = true
    })
    /** 详情数据查看 */
    this.$bus.$on('cbom-detail-view', (index, rowData) => {
      this.currentRowData = rowData
      this.isDetailData = true
    })
  },
  beforeDestroy() {
    /** 新增数据 */
    this.$bus.$off('cbom-add')
    /** 修改数据 */
    this.$bus.$off('cbom-edit')
    /** 详情数据查看 */
    this.$bus.$off('cbom-detail-view')
  },

  methods: {
    /** 查看 */
    rowView(item) {},
    /** 加载专案 */
    async getProjectList() {
      try {
        const res = await projectSimpleList({})
        this.projectList = res.data
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>
